package fr.umlv.escapeir.painters;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;

public class ImageLoader {
	
	private static Image explosion;
	
	public static Image getExplosionImage () throws IOException {
		if (explosion == null)
			explosion = ImageLoader.load("fr/umlv/escapeir/painters/images/boom.png");
		return explosion;
	}
	
	public static Image load(String file) throws IOException {
		InputStream stream = ImageLoader.class.getClassLoader().getResourceAsStream(file);
		if (stream == null) {
	        throw new IOException("Could not load the ressource "+file+" from CLASSPATH");
		}
		BufferedImage img = ImageIO.read(stream);
		stream.close();
		if (img == null) {
	        throw new IOException("Unreadable image "+file);
		}
	    return img;
	}
}
